<?php

namespace App\Service\UserCenter\v1_1_4;

use App\Helpers\AliyunUtil;
use App\Model\ProfileVerifyLog;
use App\Model\Setting\SettingUserQuestion;
use App\Model\Setting\SettingUserTags;
use App\Model\UserProfile;
use App\Model\UserQa;
use App\Model\UserTag;
use App\Service\BaseService;

/**
 * 我的个人资料-额外
 */
class MyProfileExtraService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $profile = UserProfile::getProfile($userId);
        //视频
        $ret['poster'] = [];
        $video = $profile->video ? json_decode($profile->video, true) : [];
        $video && $ret['poster'][] = [
            'link' => AliyunUtil::VOICE_HOST . $video['link'],
            'name' => $video['link'],
            'status' => ProfileVerifyLog::checkVerified($userId, ProfileVerifyLog::TYPE_VIDEO),
            'type' => 2,
        ];
        //照片列表
        $posters = !$profile->poster ? [] : explode(',', $profile->poster);
        // $posterStatus = ProfileVerifyLog::checkVerified($userId, ProfileVerifyLog::TYPE_POSTER);
        $checkingPosters = ProfileVerifyLog::getVerfingPosters($userId);
        $posters = array_unique(array_merge($posters, $checkingPosters));
        foreach ($posters as &$poster) {
            $poster = [
                'link' => AliyunUtil::imageResize(AliyunUtil::IMG_HOST . $poster),
                'name' => $poster,
                'status' => in_array($poster, $checkingPosters) ? 0 : 1,
                'type' => 1,
            ];
        }
        $ret['poster'] = array_merge($ret['poster'], $posters);
        //个性标签
        $ret['tags'] = UserTag::getTagIds($userId, UserTag::TYPE_SELF);
        $ret['tags_total'] = SettingUserTags::getTotalNum(0, $profile->gender); //config('busi.user_tag_max');
        //喜欢的标签
        $ret['love_tags'] = UserTag::getTagIds($userId, UserTag::TYPE_LOVE);
        $ret['love_tags_total'] = SettingUserTags::getTotalNum(SettingUserTags::TYPE_LOVE_TAG, $profile->gender);
        //专访
        $ret['question'] = UserQa::getList($userId, $profile->gender);
        $ret['question_total'] = SettingUserQuestion::getTotalNum($profile->gender);

        //金币领取
        $female = $profile->gender == 0;
        $ret['reward_text'] = [
            // 'voice' => $female || $profile->voice ? '' : '完善基本资料+2金币',
            // 'poster' => $female || $profile->poster ? '' : '完善照片墙+2金币',
            // 'profile' => $female || $profile->city ? '' : '完善个人信息+2金币',
            // 'self_intro' => $female || $profile->self_intro ? '' : '完善个人签名+2金币',
            // 'tags' => $female || $ret['tags'] ? '' : '完善个性标签+2金币',
            // 'question' => $female || $ret['question'] ? '' : '完善专访+2金币',
            'voice' => '',
            'poster' => '',
            'profile' => '',
            'self_intro' => '',
            'tags' => '',
            'question' => '',
            'love_tags' => '',
            'social_profile' => '',
        ];
        check_dev_env() && log_user_result($userId, $ret);
        return $ret;
    }
}
